from openai import OpenAI
import requests

API_KEY = "LSOwSFOv0bS9gFQqqhFkm7BQ1"
SECRET_KEY = "Zl6xHpSfTOgwTIifU1jBm48Qnr2kSDU4"

def get_access_token():
    """
    使用 AK，SK 生成鉴权签名（Access Token）
    :return: access_token，或是None(如果错误)
    """
    url = "https://aip.baidubce.com/oauth/2.0/token"
    params = {"grant_type": "client_credentials", "client_id": API_KEY, "client_secret": SECRET_KEY}
    return str(requests.post(url, params=params).json().get("access_token"))



import os
import qianfan
os.environ["QIANFAN_AK"] = API_KEY
os.environ["QIANFAN_SK"] = SECRET_KEY

#【推荐】建议您在生产环境使用IAM认证鉴权，文档地址 https://cloud.baidu.com/doc/Reference/s/9jwvz2egb
# os.environ["QIANFAN_ACCESS_KEY"] = "your_iam_ak"
# os.environ["QIANFAN_SECRET_KEY"] = "your_iam_sk"



resp = qianfan(endpoint="deepseek-r1", messages=[{"role":"user","content":"你是谁","key":"1"}], temperature=0.8, top_p=0.8, penalty_score=1, collapsed=True)
print(resp.body)